﻿using System;
using System.Collections.Generic;
using System.Data;
using DAL;
using Entities;

namespace BLL
{
    public class BLL_NewsGroup
    {
        private DAL_NewsGroup dal_NewsGroup = new DAL_NewsGroup();

        public DataTable Get_All_NewsGroup()
        {
            return dal_NewsGroup.Get_All_NewsGroup();
        }

        public DataTable Get_NewsGroup_ByID(Int32 p_group_id)
        {
            return dal_NewsGroup.Get_NewsGroup_ByID(p_group_id);
        }

        public List<NewsGroup> Lst_NewsGroup(DataTable pdt)
        {
            List<NewsGroup> lstReturn = new List<NewsGroup>();
            if (pdt != null && pdt.Rows.Count > 0)
            {
                foreach (DataRow dr in pdt.Rows)
                {
                    NewsGroup newsGroup = new NewsGroup();
                    newsGroup.group_id = Convert.ToInt32(dr["Group_id"]);
                    newsGroup.group_name = Convert.ToString(dr["Group_name"]);
                    newsGroup.parent_id = (dr["Parent_id"] == DBNull.Value ? 0 : Convert.ToInt32(dr["Parent_id"]));                    
                    lstReturn.Add(newsGroup);
                }
            }
            return lstReturn;
        }

        public bool InsertNewsGroup(NewsGroup pNewsGroup)
        {
            return dal_NewsGroup.InsertNewsGroup(pNewsGroup);
        }

        public bool UpdateNewsGroup(NewsGroup pNewsGroup)
        {
            return dal_NewsGroup.UpdateNewsGroup(pNewsGroup);
        }

        public bool DeleteNewsGroup(Int32 p_group_id)
        {
            return dal_NewsGroup.DeleteNewsGroup(p_group_id);
        }
    }
}
